﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.IO;
using System.Windows.Forms;
using Microsoft.Win32;

namespace delge_squirreleditor
{
    /// <summary>
    /// Interaction logic for Dialog_NewProject.xaml
    /// </summary>
    public partial class Dialog_NewProject : Window
    {
        public Dialog_NewProject()
        {
            InitializeComponent();

            buttonCreate.Click += new RoutedEventHandler(buttonCreate_Click);
            buttonBrowse.Click += new RoutedEventHandler(buttonBrowse_Click);
        }

        public string ProjectName
        {
            get { return textBoxProjectName.Text; }
            set { textBoxProjectName.Text = value; }
        }

        public string ProjectPath
        {
            get { return textBoxProjectPath.Text; }
            set { textBoxProjectPath.Text = value; }
        }

        public string FileName
        {
            get { return ProjectName + ".prj"; }
        }

        public string FilePath
        {
            get { return ProjectPath + "\\" + FileName; }
        }

        public bool CreateDirectory
        {
            get { return (bool)checkboxCreateDirectory.IsChecked; }
        }

        private bool IsVaildProjectName()
        {
            if (ProjectName.Length <= 0)
            {
                System.Windows.MessageBox.Show("Please enter a project name", "Delge Squirrel Editor", MessageBoxButton.OK, MessageBoxImage.Error);
                return false;
            }
            if (ProjectName.Length > Project.MaxFilenameLength)
            {
                System.Windows.MessageBox.Show("Project name to long, please shorten it (Can be no longer than 25 characters)", "Delge Squirrel Editor", MessageBoxButton.OK, MessageBoxImage.Error);
                return false;
            }

            return true;
        }

        public void buttonBrowse_Click(object sender, RoutedEventArgs e)
        {
            FolderBrowserDialog folderBrowseDialog = new FolderBrowserDialog();
            folderBrowseDialog.SelectedPath = textBoxProjectPath.Text;
            DialogResult result = folderBrowseDialog.ShowDialog();
            if (result == System.Windows.Forms.DialogResult.OK)
            {
                textBoxProjectPath.Text = folderBrowseDialog.SelectedPath;
                textBoxProjectPath.CaretIndex = textBoxProjectPath.Text.Length;
                textBoxProjectPath.ScrollToEnd();
            }
        }

        public void buttonCreate_Click(object sender, RoutedEventArgs e)
        {
            if (IsVaildProjectName())
                DialogResult = true;
        }
    }
}
